<?php
/**
 * WC_HelloWorld04_Setting
 * Author: PhongND
 * Author URI: http://www.facebook.com/
 * @package     WooCommerce/Admin
 * Version: 1.0
 */
 
if ( ! defined( 'ABSPATH' ) ) {
	exit; // Exit if accessed directly
}



if ( ! class_exists( 'WC_HelloWorld04_Setting' ) ) :


class WC_HelloWorld04_Setting extends WC_Settings_Page {

    /**
     * Constructor
     */
    public function __construct() {

        $this->id    = 'wc_hw04id';

        add_filter( 'woocommerce_settings_tabs_array', array( $this, 'add_settings_tab' ), 50 );
        add_action( 'woocommerce_sections_' . $this->id, array( $this, 'output_sections' ) );
        add_action( 'woocommerce_settings_' . $this->id, array( $this, 'output' ) );
        add_action( 'woocommerce_settings_save_' . $this->id, array( $this, 'save' ) );

    }

    /**
     * Add plugin options tab
     *
     * @return array
     */
    public function add_settings_tab( $settings_tabs ) {
        $settings_tabs[$this->id] = __( 'Hello04.1', 'wc_h04_domain' );
        // $settings_tabs['asdasd'] = __( 'Hello04.2', 'wc_h04_domain' );
z    }

    /**
     * Get sections
     *
     * @return array
     */
    public function get_sections() {

        $sections = array(
            ''         => __( 'Plugin Options', 'wc_h04_domain' ), // okok, remove "section-0"
            'section-1'         => __( 'Section 1', 'wc_h04_domain' ),
            'section 2'         => __( 'Section 2', 'wc_h04_domain' ),

        );

        return apply_filters( 'woocommerce_get_sections_' . $this->id, $sections );
    }


    /**
     * Get sections
     *
     * @return array
     */
    public function get_settings( $section = null ) {

        switch( $section ){

            case '' :
                $settings = array(
                    'section_title' => array(
                        'name'     => __( 'Main Section Title', 'wc_h04_domain' ),
                        'type'     => 'title',
                        'desc'     => '',
                        'id'       => 'wc_settings_tab_demo_title_section-1'
                    ),
                    'title' => array(
                        'name' => __( 'Main Title', 'wc_h04_domain' ),
                        'type' => 'text',
                        'desc' => __( 'This is some helper text', 'wc_h04_domain' ),
                        'id'   => 'wc_settings_tab_demo_title_section-1'
                    ),
                    'check01' => array(
                        'name' => __( 'Check it', 'wc_h04_domain' ),
                        'type' => 'checkbox',
                        'desc' => __( 'This is some helper text', 'wc_h04_domain' ),
                        'id'   => 'hw04_chk01'
                    ),
                    'description' => array(
                        'name' => __( 'Main Description', 'wc_h04_domain' ),
                        'type' => 'textarea',
                        'desc' => __( 'This is a paragraph describing the setting. Lorem ipsum yadda yadda yadda. Lorem ipsum yadda yadda yadda. Lorem ipsum yadda yadda yadda. Lorem ipsum yadda yadda yadda.', 'wc_h04_domain' ),
                        'id'   => 'hw04_desc01'
                    ),
                    'section_end' => array(
                         'type' => 'sectionend',
                         'id' => 'wc_settings_tab_demo_end-section-1'
                    )
                );

            break;
            case 'section-1':
                $settings = array(
                    'section_title' => array(
                        'name'     => __( 'Section One Title', 'wc_h04_domain' ),
                        'type'     => 'title',
                        'desc'     => '',
                        'id'       => 'wc_settings_tab_demo_section_title_section-2'
                    ),
                    'title' => array(
                        'name' => __( 'Section One Title', 'wc_h04_domain' ),
                        'type' => 'text',
                        'desc' => __( 'This is some helper text', 'wc_h04_domain' ),
                        'id'   => 'wc_settings_tab_demo_title_section-2'
                    ),
                    'description' => array(
                        'name' => __( 'Section One Description', 'wc_h04_domain' ),
                        'type' => 'textarea',
                        'desc' => __( 'This is a paragraph describing the setting. Lorem ipsum yadda yadda yadda. Lorem ipsum yadda yadda yadda. Lorem ipsum yadda yadda yadda. Lorem ipsum yadda yadda yadda.', 'wc_h04_domain' ),
                        'id'   => 'wc_settings_tab_demo_description_section-2'
                    ),
                    'section_end' => array(
                         'type' => 'sectionend',
                         'id' => 'wc_settings_tab_demo_section_end_section-2'
                    )
                );
            break;
            case 'section-2':
                $settings = array(
                    'section_title' => array(
                        'name'     => __( 'Section Two Title', 'wc_h04_domain' ),
                        'type'     => 'title',
                        'desc'     => '',
                        'id'       => 'wc_settings_tab_demo_section_title'
                    ),
                    'title' => array(
                        'name' => __( 'Section Two Title', 'wc_h04_domain' ),
                        'type' => 'text',
                        'desc' => __( 'This is some helper text', 'wc_h04_domain' ),
                        'id'   => 'wc_settings_tab_demo_title'
                    ),
                    'description' => array(
                        'name' => __( 'Section Two Description', 'wc_h04_domain' ),
                        'type' => 'textarea',
                        'desc' => __( 'This is a paragraph describing the setting. Lorem ipsum yadda yadda yadda. Lorem ipsum yadda yadda yadda. Lorem ipsum yadda yadda yadda. Lorem ipsum yadda yadda yadda.', 'wc_h04_domain' ),
                        'id'   => 'wc_settings_tab_demo_description'
                    ),
                    'section_end' => array(
                         'type' => 'sectionend',
                         'id' => 'wc_settings_tab_demo_section_end'
                    )
                );


            break;

        }

        return apply_filters( 'wc_settings_helloworld04', $settings, $section );

    }

    /**
     * Output the settings
     */
    public function output() {
        global $current_section;
		if ($current_section) // trim($current_section) == ""
		{
			$settings = $this->get_settings( $current_section );
			
		}
		else
		{
			$settings = $this->get_settings("");
		}
        
        WC_Admin_Settings::output_fields( $settings );
    }


    /**
     * Save settings
     */
    public function save() {
        global $current_section;
        $settings = $this->get_settings( $current_section );
        WC_Admin_Settings::save_fields( $settings );
    }

}

return new WC_HelloWorld04_Setting();

endif;

